package com.ants.platform.core.service;

import com.ants.platform.core.bean.Page;
import com.ants.platform.core.bean.Request;
import com.ants.platform.core.db.mybatis.MyBatisDAO;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 对请求日志进行操作
 * Created by liushun on 2016/8/22.
 */
@Service
public class RequestLogService {

    @Autowired
    private MyBatisDAO _dao;

    /**
     * 存储请求信息
     * @param req
     */
    public void save(Request req){
        _dao.insert("RequestLogMapper.add", req);
    }

    public Page getList(int pageNum, int pageSize, String orderField, String orderDirection){
        PageHelper.startPage(pageNum, pageSize);
        if(orderField!=null&&orderDirection!=null)
            PageHelper.orderBy(orderField+" "+orderDirection);
        else
            PageHelper.orderBy("request_time desc");
        List list = _dao.selectList("RequestLogMapper.getList");
        Page page = new Page(list);
        return page;
    }

}
